/** m2settings is a GUI to configure Maven 2 settings.xml 
 * 
 *  Copyright (C) 2007 Regis Decamps <decamps@users.sf.net>
 * 
 *  This file is part of m2settings.
 *
 *  m2settings is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version. 
 *
 *  Foobar is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with Foobar; if not, write to the Free Software
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 *  or read it online http://www.gnu.org/licenses/gpl.txt
 *
 **/
/*
 * JAddServer.java
 *
 * Created on April 15, 2007, 4:01 PM
 */

package info.decamps.m2settings.swing;

import info.decamps.m2settings.beans.Permissions;
import info.decamps.m2settings.beans.MyServer;
import info.decamps.m2settings.documentation.DocumentationProvider;
import info.decamps.m2settings.model.ServerTableModel;

import info.decamps.m2settings.model.Servers;
import info.decamps.m2settings.model.Settings;
import org.apache.log4j.Logger;
import org.jdom.Parent;

/**
 * This windows helps to add a Server.
 *
 * @author  regis
 */
public class JFrameServer extends javax.swing.JFrame {
    private Logger log = Logger.getLogger(JFrameServer.class);
    private ServerTableModel serversModel;
    private MyServer server;
    private int index=-1;
    private DocumentationProvider documentation=DocumentationProvider.getInstance();
    /** Creates new form JAddServer and create a new server.
     */
    public JFrameServer(ServerTableModel model) {
        serversModel=model;
        server=new MyServer();
        initComponents();
    }
    
    /**
     *Edit existing Server
     */
    public JFrameServer(ServerTableModel model, int index) {
        serversModel=model;
        this.index=index;
        this.server=new MyServer(model.getRow(index));
        initComponents();
    }
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
    private void initComponents() {
        buttonGroup1 = new javax.swing.ButtonGroup();
        jLabelId = new javax.swing.JLabel();
        jTextFieldId = new javax.swing.JTextField();
        jLabelUsername = new javax.swing.JLabel();
        jLabelPassword = new javax.swing.JLabel();
        jTextFieldUsername = new javax.swing.JTextField();
        jRadioButtonPassword = new javax.swing.JRadioButton();
        jRadioButtonKey = new javax.swing.JRadioButton();
        jTextFieldKeyfile = new javax.swing.JTextField();
        jButtonKeyfileBrowse = new javax.swing.JButton();
        jLabelDirectoryPermissions = new javax.swing.JLabel();
        jLabelFilePermissions = new javax.swing.JLabel();
        jLabelpassphrase = new javax.swing.JLabel();
        jCheckBoxFileUserRead = new javax.swing.JCheckBox();
        jCheckBoxFileUserWrite = new javax.swing.JCheckBox();
        jCheckBoxFileUserExec = new javax.swing.JCheckBox();
        jCheckBoxFileGroupRead = new javax.swing.JCheckBox();
        jCheckBoxFileOtherRead = new javax.swing.JCheckBox();
        jCheckBoxFileGroupWrite = new javax.swing.JCheckBox();
        jCheckBoxFileGroupExec = new javax.swing.JCheckBox();
        jCheckBoxFileOtherWrite = new javax.swing.JCheckBox();
        jCheckBoxFileOtherExec = new javax.swing.JCheckBox();
        jLabelUserFilePerms = new javax.swing.JLabel();
        jLabelGroupFilePerms = new javax.swing.JLabel();
        jLabelOtherFilePerms = new javax.swing.JLabel();
        jLabelUserDirPerm = new javax.swing.JLabel();
        jLabelGroupDirPerm = new javax.swing.JLabel();
        jLabelOtherDirPerm = new javax.swing.JLabel();
        jCheckBoxDirUserRead = new javax.swing.JCheckBox();
        jCheckBoxDirGroupRead = new javax.swing.JCheckBox();
        jCheckBoxDirOtherRead = new javax.swing.JCheckBox();
        jCheckBoxDirUserWrite = new javax.swing.JCheckBox();
        jCheckBoxDirGroupWrite = new javax.swing.JCheckBox();
        jCheckBoxDirOtherWrite = new javax.swing.JCheckBox();
        jCheckBoxDirUserExec = new javax.swing.JCheckBox();
        jCheckBoxDirGroupExec = new javax.swing.JCheckBox();
        jCheckBoxDirOtherExec = new javax.swing.JCheckBox();
        jButtonOK = new javax.swing.JButton();
        jButtonCancel = new javax.swing.JButton();
        jPasswordFieldPassword = new javax.swing.JPasswordField();
        jPasswordFieldPassphrase = new javax.swing.JPasswordField();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        jLabelId.setText("id");

        jTextFieldId.setText(server.getId());

        jLabelUsername.setText("user name");

        jLabelPassword.setText("password");

        jTextFieldUsername.setText(server.getUsername());
        jTextFieldUsername.setToolTipText(documentation.getDescription("/Server/username"));

        buttonGroup1.add(jRadioButtonPassword);
        jRadioButtonPassword.setText("password");
        jRadioButtonPassword.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
        jRadioButtonPassword.setMargin(new java.awt.Insets(0, 0, 0, 0));

        buttonGroup1.add(jRadioButtonKey);
        jRadioButtonKey.setText("key");
        jRadioButtonKey.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
        jRadioButtonKey.setMargin(new java.awt.Insets(0, 0, 0, 0));

        jTextFieldKeyfile.setText(server.getPrivatekey());
        jTextFieldKeyfile.setToolTipText(documentation.getDescription("/Server/privateKey"));

        jButtonKeyfileBrowse.setText("key file");
        jButtonKeyfileBrowse.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonKeyfileBrowseActionPerformed(evt);
            }
        });

        jLabelDirectoryPermissions.setText("Directory permissions");
        jLabelDirectoryPermissions.setToolTipText(documentation.getDescription("/Server/directoryPermissions"));

        jLabelFilePermissions.setText("File permissions");
        jLabelFilePermissions.setToolTipText(documentation.getDescription("/Server/filePermissions"));

        jLabelpassphrase.setText("pass phrase");

        jCheckBoxFileUserRead.setSelected(server.isFileUserRead());
        jCheckBoxFileUserRead.setText("read");
        jCheckBoxFileUserRead.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
        jCheckBoxFileUserRead.setMargin(new java.awt.Insets(0, 0, 0, 0));

        jCheckBoxFileUserWrite.setSelected(server.isFileUserWrite());
        jCheckBoxFileUserWrite.setText("write");
        jCheckBoxFileUserWrite.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
        jCheckBoxFileUserWrite.setMargin(new java.awt.Insets(0, 0, 0, 0));

        jCheckBoxFileUserExec.setSelected(server.isFileUserExec()
        );
        jCheckBoxFileUserExec.setText("execute");
        jCheckBoxFileUserExec.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
        jCheckBoxFileUserExec.setMargin(new java.awt.Insets(0, 0, 0, 0));

        jCheckBoxFileGroupRead.setSelected(server.isFileGroupRead());
        jCheckBoxFileGroupRead.setText("read");
        jCheckBoxFileGroupRead.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
        jCheckBoxFileGroupRead.setMargin(new java.awt.Insets(0, 0, 0, 0));

        jCheckBoxFileOtherRead.setSelected(server.isFileOtherRead());
        jCheckBoxFileOtherRead.setText("read");
        jCheckBoxFileOtherRead.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
        jCheckBoxFileOtherRead.setMargin(new java.awt.Insets(0, 0, 0, 0));

        jCheckBoxFileGroupWrite.setSelected(server.isFileGroupWrite());
        jCheckBoxFileGroupWrite.setText("write");
        jCheckBoxFileGroupWrite.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
        jCheckBoxFileGroupWrite.setMargin(new java.awt.Insets(0, 0, 0, 0));

        jCheckBoxFileGroupExec.setSelected(server.isFileGroupExec());
        jCheckBoxFileGroupExec.setText("execute");
        jCheckBoxFileGroupExec.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
        jCheckBoxFileGroupExec.setMargin(new java.awt.Insets(0, 0, 0, 0));

        jCheckBoxFileOtherWrite.setSelected(server.isFileOtherWrite());
        jCheckBoxFileOtherWrite.setText("write");
        jCheckBoxFileOtherWrite.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
        jCheckBoxFileOtherWrite.setMargin(new java.awt.Insets(0, 0, 0, 0));

        jCheckBoxFileOtherExec.setSelected(server.isFileOtherExec());
        jCheckBoxFileOtherExec.setText("execute");
        jCheckBoxFileOtherExec.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
        jCheckBoxFileOtherExec.setMargin(new java.awt.Insets(0, 0, 0, 0));

        jLabelUserFilePerms.setText("user");

        jLabelGroupFilePerms.setText("group");

        jLabelOtherFilePerms.setText("other");

        jLabelUserDirPerm.setText("user");

        jLabelGroupDirPerm.setText("group");

        jLabelOtherDirPerm.setText("other");

        jCheckBoxDirUserRead.setSelected(server.isDirUserRead());
        jCheckBoxDirUserRead.setText("read");
        jCheckBoxDirUserRead.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
        jCheckBoxDirUserRead.setMargin(new java.awt.Insets(0, 0, 0, 0));

        jCheckBoxDirGroupRead.setSelected(server.isDirGroupRead());
        jCheckBoxDirGroupRead.setText("read");
        jCheckBoxDirGroupRead.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
        jCheckBoxDirGroupRead.setMargin(new java.awt.Insets(0, 0, 0, 0));

        jCheckBoxDirOtherRead.setSelected(server.isDirOtherRead());
        jCheckBoxDirOtherRead.setText("read");
        jCheckBoxDirOtherRead.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
        jCheckBoxDirOtherRead.setMargin(new java.awt.Insets(0, 0, 0, 0));

        jCheckBoxDirUserWrite.setSelected(server.isDirUserWrite());
        jCheckBoxDirUserWrite.setText("write");
        jCheckBoxDirUserWrite.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
        jCheckBoxDirUserWrite.setMargin(new java.awt.Insets(0, 0, 0, 0));

        jCheckBoxDirGroupWrite.setSelected(server.isDirGroupWrite());
        jCheckBoxDirGroupWrite.setText("write");
        jCheckBoxDirGroupWrite.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
        jCheckBoxDirGroupWrite.setMargin(new java.awt.Insets(0, 0, 0, 0));

        jCheckBoxDirOtherWrite.setSelected(server.isDirOtherWrite());
        jCheckBoxDirOtherWrite.setText("write");
        jCheckBoxDirOtherWrite.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
        jCheckBoxDirOtherWrite.setMargin(new java.awt.Insets(0, 0, 0, 0));

        jCheckBoxDirUserExec.setSelected(server.isDirUserExec());
        jCheckBoxDirUserExec.setText("execute");
        jCheckBoxDirUserExec.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
        jCheckBoxDirUserExec.setMargin(new java.awt.Insets(0, 0, 0, 0));

        jCheckBoxDirGroupExec.setSelected(server.isDirGroupExec());
        jCheckBoxDirGroupExec.setText("execute");
        jCheckBoxDirGroupExec.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
        jCheckBoxDirGroupExec.setMargin(new java.awt.Insets(0, 0, 0, 0));

        jCheckBoxDirOtherExec.setSelected(server.isDirOtherExec());
        jCheckBoxDirOtherExec.setText("execute");
        jCheckBoxDirOtherExec.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
        jCheckBoxDirOtherExec.setMargin(new java.awt.Insets(0, 0, 0, 0));

        jButtonOK.setText("OK");
        jButtonOK.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonOKActionPerformed(evt);
            }
        });

        jButtonCancel.setText("Cancel");
        jButtonCancel.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonCancelActionPerformed(evt);
            }
        });

        jPasswordFieldPassword.setText(server.getPassword());
        jPasswordFieldPassword.setToolTipText(documentation.getDescription("/Server/password"));

        jPasswordFieldPassphrase.setText(server.getPassphrase());
        jPasswordFieldPassphrase.setToolTipText(documentation.getDescription("/Server/passphrase"));

        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .addContainerGap()
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(layout.createSequentialGroup()
                        .add(jRadioButtonPassword)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(jRadioButtonKey))
                    .add(layout.createSequentialGroup()
                        .add(jLabelpassphrase)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(jPasswordFieldPassphrase, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 131, Short.MAX_VALUE))
                    .add(jLabelFilePermissions)
                    .add(jLabelDirectoryPermissions)
                    .add(layout.createSequentialGroup()
                        .add(jButtonKeyfileBrowse)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(jTextFieldKeyfile, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 132, Short.MAX_VALUE))
                    .add(layout.createSequentialGroup()
                        .add(jLabelPassword)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(jPasswordFieldPassword, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 145, Short.MAX_VALUE))
                    .add(layout.createSequentialGroup()
                        .add(jLabelId)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(jTextFieldId, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 194, Short.MAX_VALUE))
                    .add(layout.createSequentialGroup()
                        .add(jLabelUsername)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(jTextFieldUsername, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 141, Short.MAX_VALUE))
                    .add(layout.createSequentialGroup()
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING, false)
                            .add(org.jdesktop.layout.GroupLayout.LEADING, layout.createSequentialGroup()
                                .add(jLabelOtherDirPerm)
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .add(jCheckBoxDirOtherRead))
                            .add(org.jdesktop.layout.GroupLayout.LEADING, layout.createSequentialGroup()
                                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                                    .add(jLabelGroupDirPerm)
                                    .add(jLabelUserDirPerm))
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                                    .add(jCheckBoxDirUserRead)
                                    .add(jCheckBoxDirGroupRead))))
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(layout.createSequentialGroup()
                                .add(jCheckBoxDirOtherWrite)
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                .add(jCheckBoxDirOtherExec))
                            .add(layout.createSequentialGroup()
                                .add(jCheckBoxDirGroupWrite)
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                .add(jCheckBoxDirGroupExec))
                            .add(layout.createSequentialGroup()
                                .add(jCheckBoxDirUserWrite)
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                .add(jCheckBoxDirUserExec))))
                    .add(layout.createSequentialGroup()
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(jLabelUserFilePerms)
                            .add(jLabelGroupFilePerms)
                            .add(jLabelOtherFilePerms))
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(layout.createSequentialGroup()
                                .add(jCheckBoxFileGroupRead)
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                .add(jCheckBoxFileGroupWrite)
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                .add(jCheckBoxFileGroupExec))
                            .add(layout.createSequentialGroup()
                                .add(jCheckBoxFileUserRead)
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                .add(jCheckBoxFileUserWrite)
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                .add(jCheckBoxFileUserExec))
                            .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
                                .add(jCheckBoxFileOtherRead)
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                .add(jCheckBoxFileOtherWrite)
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                .add(jCheckBoxFileOtherExec))))
                    .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
                        .add(jButtonCancel)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 90, Short.MAX_VALUE)
                        .add(jButtonOK)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .addContainerGap()
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabelId)
                    .add(jTextFieldId, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabelUsername)
                    .add(jTextFieldUsername, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jRadioButtonPassword)
                    .add(jRadioButtonKey))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabelPassword)
                    .add(jPasswordFieldPassword, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jButtonKeyfileBrowse)
                    .add(jTextFieldKeyfile, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .add(9, 9, 9)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabelpassphrase)
                    .add(jPasswordFieldPassphrase, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jLabelFilePermissions)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
                    .add(layout.createSequentialGroup()
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(jLabelUserFilePerms)
                            .add(layout.createSequentialGroup()
                                .add(21, 21, 21)
                                .add(jLabelGroupFilePerms)))
                        .add(6, 6, 6)
                        .add(jLabelOtherFilePerms, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 15, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                    .add(layout.createSequentialGroup()
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                            .add(jCheckBoxFileUserRead)
                            .add(jCheckBoxFileUserWrite)
                            .add(jCheckBoxFileUserExec))
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                            .add(jCheckBoxFileGroupRead)
                            .add(jCheckBoxFileGroupWrite)
                            .add(jCheckBoxFileGroupExec))
                        .add(6, 6, 6)
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                            .add(jCheckBoxFileOtherRead)
                            .add(jCheckBoxFileOtherWrite)
                            .add(jCheckBoxFileOtherExec))))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jLabelDirectoryPermissions)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabelUserDirPerm)
                    .add(jCheckBoxDirUserRead)
                    .add(jCheckBoxDirUserWrite)
                    .add(jCheckBoxDirUserExec))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabelGroupDirPerm)
                    .add(jCheckBoxDirGroupRead)
                    .add(jCheckBoxDirGroupWrite)
                    .add(jCheckBoxDirGroupExec))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabelOtherDirPerm)
                    .add(jCheckBoxDirOtherRead)
                    .add(jCheckBoxDirOtherWrite)
                    .add(jCheckBoxDirOtherExec))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 37, Short.MAX_VALUE)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jButtonOK)
                    .add(jButtonCancel))
                .addContainerGap())
        );
        pack();
    }// </editor-fold>//GEN-END:initComponents
    
    private void jButtonKeyfileBrowseActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonKeyfileBrowseActionPerformed
// TODO add your handling code here:
        log.warn("Not implemented");
    }//GEN-LAST:event_jButtonKeyfileBrowseActionPerformed
    
    private void jButtonCancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonCancelActionPerformed
        dispose();
    }//GEN-LAST:event_jButtonCancelActionPerformed
    
    private void jButtonOKActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonOKActionPerformed
        server.setId(jTextFieldId.getText());
        server.setUsername(jTextFieldUsername.getText());
        server.setPassword(jPasswordFieldPassword.getPassword());
        server.setPrivateKey(jTextFieldKeyfile.getText());
        server.setPassphrase(jPasswordFieldPassphrase.getPassword());
        Permissions filePermissions=new Permissions();
        filePermissions.setUserRead(jCheckBoxFileUserRead.isSelected());
        filePermissions.setGroupRead(jCheckBoxFileGroupRead.isSelected());
        filePermissions.setOtherRead(jCheckBoxFileOtherRead.isSelected());
        filePermissions.setUserWrite(jCheckBoxFileUserWrite.isSelected());
        filePermissions.setGroupWrite(jCheckBoxFileGroupWrite.isSelected());
        filePermissions.setOtherWrite(jCheckBoxFileOtherWrite.isSelected());
        filePermissions.setUserExec(jCheckBoxFileUserExec.isSelected());
        filePermissions.setGroupExec(jCheckBoxFileGroupExec.isSelected());
        filePermissions.setOtherExec(jCheckBoxFileOtherExec.isSelected());
        server.setFilePermissions(filePermissions);
        
        Permissions directoryPermissions=new Permissions();
        directoryPermissions.setUserRead(jCheckBoxDirUserRead.isSelected());
        directoryPermissions.setGroupRead(jCheckBoxDirGroupRead.isSelected());
        directoryPermissions.setOtherRead(jCheckBoxDirOtherRead.isSelected());
        directoryPermissions.setUserWrite(jCheckBoxDirUserWrite.isSelected());
        directoryPermissions.setGroupWrite(jCheckBoxDirGroupWrite.isSelected());
        directoryPermissions.setOtherWrite(jCheckBoxDirOtherWrite.isSelected());
        directoryPermissions.setUserExec(jCheckBoxDirUserExec.isSelected());
        directoryPermissions.setGroupExec(jCheckBoxDirGroupExec.isSelected());
        directoryPermissions.setOtherExec(jCheckBoxDirOtherExec.isSelected());
        server.setDirectoryPermissions(directoryPermissions);
        
        if(index<0) {
            serversModel.addRow(server.getServer());           
        } else {
            log.debug("Server configuration changed");
            serversModel.fireChange(index);
        }
        dispose();
    }//GEN-LAST:event_jButtonOKActionPerformed
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.ButtonGroup buttonGroup1;
    private javax.swing.JButton jButtonCancel;
    private javax.swing.JButton jButtonKeyfileBrowse;
    private javax.swing.JButton jButtonOK;
    private javax.swing.JCheckBox jCheckBoxDirGroupExec;
    private javax.swing.JCheckBox jCheckBoxDirGroupRead;
    private javax.swing.JCheckBox jCheckBoxDirGroupWrite;
    private javax.swing.JCheckBox jCheckBoxDirOtherExec;
    private javax.swing.JCheckBox jCheckBoxDirOtherRead;
    private javax.swing.JCheckBox jCheckBoxDirOtherWrite;
    private javax.swing.JCheckBox jCheckBoxDirUserExec;
    private javax.swing.JCheckBox jCheckBoxDirUserRead;
    private javax.swing.JCheckBox jCheckBoxDirUserWrite;
    private javax.swing.JCheckBox jCheckBoxFileGroupExec;
    private javax.swing.JCheckBox jCheckBoxFileGroupRead;
    private javax.swing.JCheckBox jCheckBoxFileGroupWrite;
    private javax.swing.JCheckBox jCheckBoxFileOtherExec;
    private javax.swing.JCheckBox jCheckBoxFileOtherRead;
    private javax.swing.JCheckBox jCheckBoxFileOtherWrite;
    private javax.swing.JCheckBox jCheckBoxFileUserExec;
    private javax.swing.JCheckBox jCheckBoxFileUserRead;
    private javax.swing.JCheckBox jCheckBoxFileUserWrite;
    private javax.swing.JLabel jLabelDirectoryPermissions;
    private javax.swing.JLabel jLabelFilePermissions;
    private javax.swing.JLabel jLabelGroupDirPerm;
    private javax.swing.JLabel jLabelGroupFilePerms;
    private javax.swing.JLabel jLabelId;
    private javax.swing.JLabel jLabelOtherDirPerm;
    private javax.swing.JLabel jLabelOtherFilePerms;
    private javax.swing.JLabel jLabelPassword;
    private javax.swing.JLabel jLabelUserDirPerm;
    private javax.swing.JLabel jLabelUserFilePerms;
    private javax.swing.JLabel jLabelUsername;
    private javax.swing.JLabel jLabelpassphrase;
    private javax.swing.JPasswordField jPasswordFieldPassphrase;
    private javax.swing.JPasswordField jPasswordFieldPassword;
    private javax.swing.JRadioButton jRadioButtonKey;
    private javax.swing.JRadioButton jRadioButtonPassword;
    private javax.swing.JTextField jTextFieldId;
    private javax.swing.JTextField jTextFieldKeyfile;
    private javax.swing.JTextField jTextFieldUsername;
    // End of variables declaration//GEN-END:variables
    
}
